﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Ebada.Modules.Vehicle
{
    /// <summary>
    /// 车辆调度编辑
    /// </summary>
    public partial class frmVehicleDispatch_BakEdit : FormBase, IPopupFormEdit {
        SortableSearchableBindingList<mOrg> m_OrgID = new SortableSearchableBindingList<mOrg>();
        SortableSearchableBindingList<Empolyees> m_Employ= new SortableSearchableBindingList<Empolyees>();
        public static frmVehicleDispatch_BakEdit parentfrom = null;
        bool IsFirstLoad = true;
        public frmVehicleDispatch_BakEdit()
        {
            InitializeComponent();
            parentfrom = this;
        }
        private void frmVehicleDispatchEdit_Load(object sender, EventArgs e)
        {

            //ucVehicleDispatchEmp1.VehicleDispatchID = rowData.VehicleDispatchID;
            //ucVehicleDispatchEmp1.InitData("where VehicleDispatchID='" + rowData.VehicleDispatchID + "'");
            //IsFirstLoad = false;
        }
        void dataBind() 
        {

            this.txtVehicleDispatchID.DataBindings.Add("EditValue", rowData, "VehicleDispatchID");
            this.txtVehicleNumber.DataBindings.Add("EditValue", rowData, "VehicleNumber");
            this.txtEmployeeName.DataBindings.Add("EditValue", rowData, "EmployeeName");
            this.daeDispatchingTime.DataBindings.Add("EditValue", rowData, "DispatchingTime");
            this.deeReturnTime.DataBindings.Add("EditValue", rowData, "ReturnTime");
            this.txtEndKilometer.DataBindings.Add("EditValue", rowData, "EndKilometer");
            this.meReturnRemark.DataBindings.Add("EditValue", rowData, "ReturnRemark");

        }
       
        #region IPopupFormEdit Members
        private VehicleDispatch rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as VehicleDispatch;
                    dataBind();
                    InitComboBoxData();
                } else {
                    ConvertHelper.CopyTo<VehicleDispatch>(value as VehicleDispatch, rowData);
                }
            }
        }

        #endregion

        private void InitComboBoxData() 
        {
           //IList<Empolyees> empl_list = MainHelper.PlatformSqlMap.GetList<Empolyees>("");
           //this.SetComboBoxData(this.luEmployeeID, "Empolyee_Name", "Empolyee_ID", "请选择", "人员名称", empl_list);
           //IList<Vehicles> vehi_list = MainHelper.PlatformSqlMap.GetList<Vehicles>("");
           //this.SetComboBoxData2(this.luVehicleID, "VehicleNumber", "VehicleID", "请选择", "车牌号码", vehi_list);

        }
        //public int PersonNum
        //{
        //    set { txtEmployeeNum.Text = value.ToString(); }
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
       //人员选择器
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Empolyees> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        //车牌号选择器
        public void SetComboBoxData2(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Vehicles> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        
      

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (((DateTime)deeReturnTime.EditValue).Date.CompareTo(((DateTime)daeDispatchingTime.EditValue).Date)<0)
            {
                MessageBox.Show("实际回车时间不能小于实际派车时间！");
                return;
            }
            if ((Convert.ToDecimal(txtEndKilometer.EditValue) - rowData.StrartKilometer)<=0)
            {
                MessageBox.Show("返回时里程表数不能小于出车里程表数！");
                return;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

       
        private void deeExpectReturnTime_EditValueChanged(object sender, EventArgs e)
        {
            //if (IsFirstLoad)
            //{
            //    return;
            //}
            //txtUsingDays.EditValue = ((DateTime)deeReturnTime.EditValue).Subtract((DateTime)daeDispatchingTime.EditValue).Days;

        }
        ////车牌号选择
        //private void luVehicleID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        //{
        //    if (e.Button.Index == 1)
        //    {

        //        frmVehiclesSeletcter frm = new frmVehiclesSeletcter();
        //        frm.InitData_Slect("");
        //        if (frm.ShowDialog() == DialogResult.OK)
        //        {
        //            luVehicleID.Text = frm.SelectObj.VehicleNumber;
        //        }
        //    }

        //}
      

      
    }
}